﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;

namespace FreeProperty.Views.ProviderDirectory
{
    /// <summary>
    /// Summary description for ZipCodeSuggest1
    /// </summary>
    public class OfficeSuggest : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            GetOfficeNames(context);
        }
        private void GetOfficeNames(HttpContext context)
        {
            StringBuilder sbOfficeNames = new StringBuilder();
            if (!string.IsNullOrEmpty(context.Request.QueryString["q"])) // remember, 'q' is the query the autosuggest will pass
            {
                List<string> lstZipCodes = Provider.SuggestOfficeNames(context.Request.QueryString["q"]);
                foreach (var zip in lstZipCodes)
                {
                    sbOfficeNames.Append(zip).Append(Environment.NewLine);
                }
            }
            context.Response.Write(sbOfficeNames.ToString());
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}